package com.cema.manage.project.android;

import com.cema.manage.common.utils.KaptchaUtil;
import com.cema.manage.framework.config.CaptchaConfig;
import com.cema.manage.project.android.result.JsonResult;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.image.BufferedImage;

@RestController
@RequestMapping("kaptcha")
public class KaptchaController {
    @Autowired
    private CaptchaConfig captchaConfig;

    @RequestMapping("/default")
    public JsonResult defaultK() {
        DefaultKaptcha defaultKaptcha = captchaConfig.getKaptchaBeanMath();
        BufferedImage bufferedImage = defaultKaptcha.createImage("10086");
        String base64Image = KaptchaUtil.BufferedImageToBase64(bufferedImage);
        return JsonResult.returnSuccess(base64Image);
    }
}
